package com.jia.leetCode;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: Leetcode
 * @description: https://leetcode-cn.com/contest/biweekly-contest-33/problems/minimum-number-of-vertices-to-reach-all-nodes/
 * @author: STU756
 * @create: 2020-08-24 12:16
 */
public class Pro1557 {
    //求入度为0的节点即可
    public List<Integer> findSmallestSetOfVertices(int n, List<List<Integer>> edges) {
        int[] degree = new int[n];
        for(List<Integer> list : edges) {
            ++degree[list.get(1)];
        }
        List<Integer> ans = new ArrayList<>();
        for(int i = 0; i < n; i++) {
            if(degree[i] == 0)
                ans.add(i);
        }
        return ans;
    }
}
